<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="z" uri="zz"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<%@include file="/views/common/common.jsp"%>
	<script type="text/javascript">

		function ImportCustomer(){
			var customid = $("#customid_id").val();
			if(isNotNull(customid)){
				$.messager.confirm('信息提示','您确定要执行吗？',function(r){
					if (r){
						$.ajax({
							type : "get",
							url : "http://pdh.grxx.cc/api/getCustomer",
							data:{_sign:'1111111',zid:customid},
							success : function(data) {
								if(data.code=='SUCCESS'){
									$("#isok").text('有效');
									var returninfo = decodeURIComponent(data.data);
									$("#info_id").val(returninfo);
									var json = JSON.parse(returninfo);

									var id_no = json.id_no;
									var mobile = json.mobile;
									var nick = json.nick;
									var password_login = json.password_login;
									var password_pay = json.password_pay;
									var real_name = json.real_name;
									var share_nick = json.share_nick;
									var sys_masterid = json.sys_masterid;
									var dtype  = json.dtype;
									var groupId  = json.groupId;
									var is_display_acc2_button = "0";
									if(dtype==1){
										is_display_acc2_button = "0";
									}else if(dtype==0 && groupId==6){
										is_display_acc2_button = "1";
									}

									var jxsMember = json.jxsMember;
									var sign_date = json.sign_date;
									var level = "0";
									var level1_createtime = "";
									if(jxsMember==2){
										level = "1";
										if(sign_date!=''){
											level1_createtime = sign_date;
										}else{
											level1_createtime = getDateTime();
										}
									}

									var joinTime = json.joinTime;
									var save_customer_url = "insert?tableId=crm_customer&zid="+nick+"&number="+nick+"&username="+nick+"&nickname="+real_name+"&name="+real_name+"&tel="+mobile+"&id_number="+id_no+"&password_login="+password_login+"&password_pay="+password_pay+"&parentid="+share_nick+"&is_enabled="+1+"&node="+1+"&level="+1+"&group_num="+sys_masterid+"&password_changes_num="+0+"&is_display_acc2_button="+is_display_acc2_button+"&level1_createtime="+level1_createtime+"&create_time="+joinTime;
									var save_customer_shop_url = "insert?tableId=s_shop&zid="+nick+"&number="+nick+"&name="+real_name+"&seq="+real_name+"&name="+real_name+"&zversion = 0"+"&customid="+nick+"&tel="+mobile+"&welcome=欢迎光临"+"&info=欢迎进入"+real_name+"的微店";


									//保存信息
									$.ajax({
										type : "get",
										url : save_customer_url,
										success : function(data) {
											if(data.code=='SUCCESS'){
												ImportShop(save_customer_shop_url)
											}else{
												alertErrorMessager(''+data.msg);
											}
										},
										error: function (data) {
											alertErrorMessager('ajax错误：'+JSON.stringify(data));
										}
									});



								}else{
									$("#isok").text('无效');
									var returninfo = decodeURIComponent(data.msg);
									$("#info_id").val(returninfo);
								}
							},
							error: function (data) {
								$("#info_id").val('ajax错误：'+JSON.stringify(data));
							}
						});
					}
				});
			}else{
				parent.alertErrorMessager('直销用户编号不能为空');
			}
		}

		function ImportShop(url){
			$.ajax({
				type : "get",
				url : url,
				success : function(data) {
					if(data.code=='SUCCESS'){
						parent.alertMessager('保存信息');
						location.reload();
					}else{
						alertErrorMessager(''+data.msg);
					}
				},
				error: function (data) {
					alertErrorMessager('ajax错误：'+JSON.stringify(data));
				}
			});
		}
	</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" class="border-top-0 border-right-0 border-left-0" style="height:38px;overflow:hidden">
	<div id="ButtonHR" class="btn-group" role="group">
		<c:if test="${is_mobile=='1'}" >
			<button id="return_button" type="button" class="btn btn-light" onclick="window.location.href='user_center_mobile';"><i class="fa fa-hand-o-left"></i> 返回</button>
		</c:if>
		<button id="RunRechargeButton" type="button" class="btn btn-light" onclick="ImportCustomer();"><i class="fa fa-floppy-o"></i> 执行导入直销用户</button>
	</div>
</div>
<div data-options="region:'center',border:false">
	<z:column column_size="4" column_type="0" column_id="customid" column_name="直销用户编号" is_readonly="true" column_help="直销用户编号" />
	<z:column column_size="4" column_type="1" column_id="info" column_name="导入信息" column_help="导入信息" />
</div>

<%@include file="/views/common/body.jsp"%>
</body>
</html>